home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
alignd1a
/
modspace.bas
next >
Wrap
BASIC Source File
|
1999-09-05
|
2KB
|
70 lines
Attribute VB_Name = "modSpace"
Option Explicit
Public Function AlignData(iInitialSpace As Integer, sData1 As String, sData2 As String, iNumLines As Integer, CntrlType As Integer) As String
' this function will repeatedly take in two strings.
' Ex. "Product" and "12-483589-896". This would be an
' example of 2 strings that you would want to place side
' by side in a list or textbox with space between the two.
' But ofcourse you would need the next Product and code, to
' appear with same spacing underneath the previous one, but
' still stay in line.
'
' Product 12-483589-896
' Product 12-483589-897
' so on and so forth.
' By passing the two strings in the function will return
' a string formatted to match the previous one.
Static LastFormatLen As Integer
Dim LenOfMainFormat As Integer
Static StrCnt As Integer
Dim FormatStr As String
Dim ActualSpace As String
Dim LenBothStrs As Integer
Dim i As Integer
StrCnt = StrCnt + 1
' get the length of both strings combined
LenBothStrs = Len(sData1) + Len(sData1)
' is this the first set of strings?
If StrCnt = 1 Then
ActualSpace = CreateSpace(iInitialSpace)
FormatStr = sData1 & ActualSpace & sData2
If CntrlType = 1 Then
LenOfMainFormat = Len(FormatStr) - 5 ' text box
Else
LenOfMainFormat = Len(FormatStr) ' listbox
End If
LastFormatLen = LenOfMainFormat
AlignData = FormatStr
Exit Function
End If
' another string format it to the
' first one
iInitialSpace = LastFormatLen - LenBothStrs
ActualSpace = CreateSpace(iInitialSpace)
FormatStr = sData1 & ActualSpace & sData2
AlignData = FormatStr
If StrCnt = iNumLines Then
' reset all statics
' for the next use
LastFormatLen = 0
StrCnt = 0
End If
End Function
Function CreateSpace(ISpace As Integer) As String
CreateSpace = Space(ISpace)
End Function